import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'login',
    // todo 路由懒加载   import('@/views/login') == import('@/views/login/index.vue')
    component: () => import('@/views/login')
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('@/views/search')
  },
  {
    path: '/',
    // name: 'layout', // 如果父路由有默认子路由，那么它的name是没有意义的，写上去代码会报一个 warning
    component: () => import('@/views/layout'),
    // 子路由
    children: [
      {
        path: '', // 默认子路由，当访问父路由时，默认走该路由，默认子路由只能有一个
        name: 'home',
        component: () => import('@/views/home')
      },
      {
        path: '/qa',
        name: 'qa',
        component: () => import('@/views/qa')
      },
      {
        path: '/video',
        name: 'video',
        component: () => import('@/views/video')
      },
      {
        path: '/my',
        name: 'my',
        component: () => import('@/views/my')
      }
    ]
  },
  {
    path: '/article/:articleId',
    name: 'article',
    component: () => import('@/views/article'),
    // note 使用组件Props解耦路由参数（路由给路由要跳转的组件中的props传参）
    props: true // 开启 props传参，将路由动态参数映射到组件的 props 中
  },
  {
    path: '/user/profile',
    name: 'user-profile',
    component: () => import('@/views/user-profile')
  }
]

const router = new VueRouter({
  routes
})

export default router
